package com.bwie.controller;

import com.bwie.pojo.TbProd;
import com.bwie.service.TbProdService;
import com.bwie.utils.R;
import com.bwie.vo.PageInfoVo;
import com.bwie.vo.TbProdVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @description :
 * @Author QiHainan
 * @Create 2025/3/25 21:46
 * @Version 1.0
 */
@RestController
@RequestMapping("/prod/index")
public class IndexController {
    @Autowired
    private TbProdService tbProdService;

    @PostMapping("/getProdList")
    public R getProdList(@RequestBody PageInfoVo pageInfoVo){
        return tbProdService.getProdList(pageInfoVo);
    }

    /**
     * 获取字典表数据
     * @return
     */
    @PostMapping("/getDictList/{id}")
    public R getDictList(@PathVariable(name = "id") Integer id){
        return tbProdService.getDictList(id);
    }

    /**
     * 分页从Es中获取商品列表
     * @param pageInfoVo
     * @return
     */
    @PostMapping("/getProdListFromEs")
    public R getProdListFromEs(@RequestBody PageInfoVo pageInfoVo){
        return tbProdService.getProdListFromEs(pageInfoVo);
    }

    /**
     * 商品添加
     * @param tbProd
     * @return
     */
    @PostMapping("/addProd")
    public R addProd(@RequestBody TbProd tbProd){
        return tbProdService.addProd(tbProd);
    }

    /**
     * 修改商品
     * @param tbProd
     * @return
     */
    @PostMapping("/updateProd")
    public R updateProd(@RequestBody TbProd tbProd){
        return tbProdService.updateProd(tbProd);
    }

    /**
     * 删除商品
     * @param prodId
     * @return
     */
    @PostMapping("/deleteProd/{prodId}")
    public R deleteProd(@PathVariable("prodId") Integer prodId){
        return tbProdService.deleteProd(prodId);
    }

    /**
     * 商品申请上线
     * @param prodId
     * @return
     */
    @PostMapping("/applyProdOnline/{prodId}")
    public R applyProdOnline(@PathVariable("prodId") Integer prodId){
        return tbProdService.applyProdOnline(prodId);
    }

    /**
     * 扣减库存
     * @param prodList
     * @return
     */
    @PostMapping("/sucProdStock")
    public R sucProdStock(@RequestBody List<TbProdVo> prodList){
        return tbProdService.sucProdStock(prodList);
    }

    /**
     * 导出所有商品为Excel
     */
    @GetMapping("/exportProdExcel")
    public void  exportProdExcel(){
        tbProdService.exportProdExcel();
    }

    /**
     * 多选导出
     * @param ids
     */
    @GetMapping("/exportProdMore/{ids}")
    public void exportProdMore(@PathVariable("ids") String ids){
        tbProdService.exportProdMore(ids);
    }

    /**
     * 导入商品列表
     * @param file
     * @return
     */
    @PostMapping("/importProdExcel")
    public R importProdExcel(@RequestPart("file")MultipartFile file){
        return tbProdService.importProdExcel(file);
    }
}
